/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package app.actions;

import app.negocio.GestionLibreria;
import app.negocio.ItfzGestionLibreria;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author Johann
 */
public class ModificarPrecioLibroAction extends Action{

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        String vista = "ko";
        if (request.getParameter("modificarPrecio") != null
                && request.getParameter("isbn") != null
                && request.getParameter("precio") != null) {
            ItfzGestionLibreria gestionLibreria = new GestionLibreria();
            if (gestionLibreria.modificarPrecio(request.getParameter("isbn"),
                    Double.parseDouble(request.getParameter("precio")))) {
                request.setAttribute("libroModificadoOK", "El precio del libro ha sido modificado correctamente");
                request.setAttribute("isbn", request.getParameter("isbn"));
                vista = "ok";
            } else {
                request.setAttribute("libroModificadoKO", "ERROR: El libro no ha sido modificado");
            }
        }
        request.setAttribute("modificar", this);
        // 3.- Redirigir a la vista elegida
        return mapping.findForward(vista);
    }
    
    
}
